package com.walle.sonar.export.report.generate;

import java.util.List;

import com.walle.ak47.commons.utils.FileUtils;
import com.walle.ak47.commons.utils.StringUtils;
import com.walle.sonar.export.report.api.issues.GetIssueInfos;
import com.walle.sonar.export.report.api.issues.IssueInfo;

public class GenerateCvsForIssues {
	
	static String filePath = "E:/issues.csv" ;
	static String split = "," ;
	
	public static void generate() {
		
		FileUtils.deleteFile(filePath) ;
		GetIssueInfos getIssueInfos = new GetIssueInfos() ;
		List<IssueInfo> issues = getIssueInfos.getAllIssues();
		System.err.println(issues.size());
		
		for (IssueInfo issueInfo : issues) {
			String _strContent = issueInfo.getType()+split+StringUtils.replace(issueInfo.getShortDesc(), ",", ";")+split+issueInfo.getLine()+split+issueInfo.getComponent()+split+issueInfo.getRule()+"\n" ;
			FileUtils.appendFileText( filePath, _strContent, "UTF-8");
		}
	}
	
	public static void main(String[] args) {
		GenerateCvsForIssues.generate();
	}
}
